# -*- coding: utf-8 -*-
import pymongo


class DB:
    def __init__(self):
        self.db_inst = None
        pass

    def open(self, ip, port):
        db_url = "mongodb://" + ip + ":" + port
        print("              connect db        : ", db_url)
        self.db_inst = pymongo.MongoClient(db_url)
        return self.db_inst

    def database(self, name):
        return self.db_inst[name]

    def collect(self, db_name, collect_name):
        return self.db_inst[db_name][collect_name]

    def close(self):
        self.db_inst.close()

